package com.example.jwt.registry;

import com.example.jwt.registry.Interceptor.JwtAuthenticationInterceptor;
import com.example.jwt.registry.Interceptor.RequestLimitingInterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author Story
 * @Date 2022/3/20 0:15
 * @Version 1.0
 * 拦截器
 */
@Configuration
public class JwtInterceptorConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //默认拦截所有路径
        registry.addInterceptor(authenticationInterceptor())
                .addPathPatterns("/**");
        registry.addInterceptor(requestLimitingInterceptor())
                .addPathPatterns("/**");
    }


    @Bean
    public JwtAuthenticationInterceptor authenticationInterceptor() {
        return new JwtAuthenticationInterceptor();
    }

    @Bean
    public RequestLimitingInterceptor requestLimitingInterceptor() {
        return new RequestLimitingInterceptor();
    }
}
